//
//  FieldNode.m
//  DataCollector
//
//  Created by jiro on 12/06/29.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "FieldNode.h"

FieldNode::FieldNode( NSString* tableNameArg, NSString* fieldNameArg, NSString* aliasArg, bool isDistinctArg )
{
	tableName = tableNameArg;
	fieldName = fieldNameArg;
	alias = aliasArg;
	isDistinct = isDistinctArg;
}

FieldNode::FieldNode( NSString* tableNameArg, NSString* fieldNameArg, NSString* aliasArg )
{
	tableName = tableNameArg;
	fieldName = fieldNameArg;
	alias = aliasArg;
	isDistinct = false;
}

FieldNode::FieldNode( NSString* tableNameArg, NSString* fieldNameArg )
{
	tableName = tableNameArg;
	fieldName = fieldNameArg;
	alias = NULL;
	isDistinct = false;
}

FieldNode::FieldNode( NSString* fieldNameArg )
{
	tableName = NULL;
	fieldName = fieldNameArg;
	alias = NULL;
	isDistinct = false;
}

FieldNode::FieldNode()
{
	tableName = NULL;
	fieldName = NULL;
	alias = NULL;
	isDistinct = false;
}

NSString* FieldNode::query() const
{
	NSMutableString* s = [ NSMutableString string ];
	if ( isDistinct )
	{
		[ s appendString: @" distinct " ];
	}
	if ( tableName != NULL )
	{
		[ s appendFormat: @"%@.", tableName ];
	}
	[ s appendString: fieldName ];
	if ( alias != NULL )
	{
		[ s appendFormat: @" as %@", alias ];
	} 
	return s;

}
